//
//  CDTestViewController5.m
//  CuriosityDaily3
//
//  Created by JSY on 16/9/23.
//  Copyright © 2016年 theBestTeam. All rights reserved.
//

#import "CDTestViewController5.h"
#import "CDMyMessageCollectionViewController.h"

@interface CDTestViewController5 ()

@property(nonatomic,weak)UIView *topView;

@end

@implementation CDTestViewController5

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor randomColor];
    [self setupUI];
    [self setNavBarWithTitle:@"我的消息"];
    
}

-(void)setupUI{
    [self setTopView];
    [self setcollectionview];
}

-(void)setcollectionview{
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake(CDScreen.size.width, CDScreen.size.height - 64 - 45);
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    CDMyMessageCollectionViewController *collectionVC = [[CDMyMessageCollectionViewController alloc]initWithCollectionViewLayout:layout];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

    [self addChildViewController:collectionVC];
    [self.view addSubview:collectionVC.collectionView];
    
    [collectionVC.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView.mas_bottom);
        make.left.right.bottom.equalTo(self.view);
    }];

}

-(void)setTopView{
    UIView *topview = [[UIView alloc]init];
    topview.backgroundColor = [UIColor randomColor];
    self.topView = topview;
    [self.view addSubview:topview];
    
    [topview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(64);
        make.left.right.offset(0);
        make.height.offset(45);
    }];
    
    UIButton *commentBtn = [self createButtonWithTitle:@"评论"];
    UIButton *praiseBtn = [self createButtonWithTitle:@"点赞"];
    UIButton *systemMessageBtn = [self createButtonWithTitle:@"系统消息"];
    [topview addSubview:commentBtn];
    [topview addSubview:praiseBtn];
    [topview addSubview:systemMessageBtn];
    
    [commentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(topview);
        make.right.equalTo(praiseBtn.mas_left);
        make.bottom.equalTo(topview.mas_bottom).offset(-2);
    }];
    
    [praiseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(commentBtn);
        make.bottom.equalTo(commentBtn);
        make.right.equalTo(systemMessageBtn.mas_left);
        make.width.equalTo(commentBtn);
    }];
    
    [systemMessageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(commentBtn);
        make.bottom.equalTo(commentBtn);
        make.right.equalTo(topview);
        make.width.equalTo(praiseBtn.mas_width);
    }];
    
}

-(UIButton *)createButtonWithTitle:(NSString *)title {
    UIButton *btn = [[UIButton alloc]init];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
    
    return btn;
}

@end
